home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c
- Subject: Re: I need help.
- Date: 29 Mar 1996 09:52:30 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4jh0vu$13c@solutions.solon.com>
- References: <4j9hr7$skj@cronkite.seas.gwu.edu> <26MAR199615081545@erich.triumf.ca> <danpop.828046690@rscernix> <4jguak$n6e@news1.intercall.com>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4jguak$n6e@news1.intercall.com>,
- Steven Ovits <engevar@intercall.com> wrote:
- >"EOF which expands to an integral constant expression that is
- >returned by several functions to indicate 'end-of-file,' that is,
- >no more input from a stream."
-
- >Notice it says nothing about whether the constant is valid in a file,
- >so it can be.
-
- However, you miss two important points:
- 1. All getchar type routines return the character *converted to unsigned
- char* and then converted to int.
- 2. EOF is negative.
-
- Unless sizeof(char) == sizeof(int), it is *impossible* for getchar()
- (or getc, or fgetc) to return EOF on a file that has not reached the
- end of file, i.e., it is impossible for getchar() to return EOF and
- feof() to return 0.
-
- >Therefore, it is a good idea to always use feof and only feof to
- >test for the end of input.
-
- This is untrue. If you're willing to give up support for machines where
- char is the same size as int, you can use EOF safely. Even on those
- machines, it may be safe to use EOF, if no value returned by getchar()
- from a file read will ever compare equal to EOF, which is (AFAICT)
- permissible.
-
- In any event, even on such machines, testing for EOF, and then testing for
- feof(), will allow you to avoid the call to feof() for the vast majority
- of characters. This is a good deal.
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-